package o;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.os.Build.VERSION;
import android.widget.RemoteViews;
import android.widget.TextView;
import androidx.annotation.IdRes;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat.d;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.GlideException;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appmarket.support.audio.AudioBean;
import com.huawei.appmarket.support.audio.AudioPlayReceiver;
import com.huawei.appmarket.support.audio.notification.AudioNotificationJumpActivity;
import com.huawei.appmarket.support.audio.notification.AudioNotificationReceiver;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.lang.ref.WeakReference;
import java.util.Formatter;
import java.util.Locale;
import o.dky.h;
import o.dky.i;
import o.dky.j;
import o.dky.k;

public class epn {
    private static volatile epn ˋ;
    private NotificationManager ʻ = ((NotificationManager) this.ॱ.getSystemService("notification"));
    private RemoteViews ʼ;
    private Notification ʽ;
    private Formatter ˊ = new Formatter(this.ˏ, Locale.getDefault());
    private AudioBean ˎ;
    private final StringBuilder ˏ = new StringBuilder();
    private epd ͺ = new c(this);
    private Context ॱ = ContentManager.getInstant().getContext();
    private AudioPlayReceiver ॱॱ;
    private boolean ᐝ = ͺ();

    static class a implements zn<Bitmap> {
        private WeakReference<epn> ॱ;

        public a(epn o_epn) {
            this.ॱ = new WeakReference(o_epn);
        }

        public boolean ॱ(@Nullable GlideException glideException, Object obj, zz<Bitmap> zzVar, boolean z) {
            epn o_epn = (epn) this.ॱ.get();
            if (!(o_epn == null || o_epn.ʼ == null)) {
                AudioBean ॱ = epe.ˏ().ॱ();
                if (ॱ != null) {
                    o_epn.ʼ.setImageViewResource(h.ˋ, dgm.ˊ(ॱ.ॱॱ()));
                    o_epn.ʼ();
                }
            }
            return true;
        }

        public boolean ˎ(Bitmap bitmap, Object obj, zz<Bitmap> zzVar, rz rzVar, boolean z) {
            epn o_epn = (epn) this.ॱ.get();
            if (!(o_epn == null || o_epn.ʼ == null)) {
                o_epn.ʼ.setImageViewBitmap(h.ˋ, bitmap);
                o_epn.ʼ();
            }
            return true;
        }
    }

    static class c implements epd {
        private WeakReference<epn> ˋ;

        public c(epn o_epn) {
            this.ˋ = new WeakReference(o_epn);
        }

        public void ˊ(AudioBean audioBean) {
            epn o_epn = (epn) this.ˋ.get();
            if (o_epn != null) {
                o_epn.ˎ(audioBean);
            }
        }

        public void ˊ(int i) {
        }

        public void ॱ(int i, int i2) {
            epn o_epn = (epn) this.ˋ.get();
            if (o_epn != null) {
                o_epn.ॱ(o_epn.ˎ);
                o_epn.ʼ();
            }
        }

        public void ˋ(int i) {
        }

        public void ˎ() {
            epn o_epn = (epn) this.ˋ.get();
            if (o_epn != null) {
                o_epn.ʽ();
                o_epn.ʼ();
            }
        }

        public void ˋ() {
            epn o_epn = (epn) this.ˋ.get();
            if (o_epn != null) {
                o_epn.ॱ(o_epn.ˎ);
                o_epn.ʽ();
                o_epn.ʼ();
            }
        }

        public void ˋ(int i, String str) {
            epn o_epn = (epn) this.ˋ.get();
            if (o_epn != null) {
                o_epn.ʽ();
                o_epn.ʼ();
            }
        }
    }

    private epn() {
    }

    public static epn ˎ() {
        if (ˋ == null) {
            synchronized (epn.class) {
                if (ˋ == null) {
                    ˋ = new epn();
                }
            }
        }
        return ˋ;
    }

    public Notification ˋ(AudioBean audioBean) {
        boolean z = false;
        this.ˎ = audioBean;
        if (this.ˎ == null) {
            return null;
        }
        this.ˊ = new Formatter(this.ˏ, Locale.getDefault());
        int ˊ = dgm.ˊ(audioBean.ॱॱ());
        d ˎ = new d(this.ॱ).ˊ(ˊ).ˎ(ˊॱ()).ˊ(true).ˊ(ॱॱ()).ॱ(true).ˏ(new long[]{0}).ˎ(null).ˎ(false).ˎ("audio.group");
        if (VERSION.SDK_INT >= 26) {
            NotificationChannel notificationChannel = new NotificationChannel("notification.channel.audio", this.ॱ.getString(j.ᐝˊ), 3);
            notificationChannel.enableVibration(false);
            notificationChannel.setVibrationPattern(new long[]{0});
            notificationChannel.setSound(null, null);
            if (this.ʻ.getNotificationChannel(notificationChannel.getId()) == null) {
                this.ʻ.createNotificationChannel(notificationChannel);
            }
            ˎ.ˋ(notificationChannel.getId());
        }
        this.ʼ = new RemoteViews(this.ॱ.getPackageName(), ˋॱ());
        if (VERSION.SDK_INT > 23) {
            z = true;
        }
        if (this.ᐝ) {
            int color = this.ॱ.getResources().getColor(dky.d.ॱˎ);
            int color2 = this.ॱ.getResources().getColor(dky.d.ॱᐝ);
            if (z) {
                this.ʼ.setTextColor(h.ʽᐝ, color);
            }
            this.ʼ.setTextColor(h.ˊ, color);
            this.ʼ.setTextColor(h.ˏ, color2);
            this.ʼ.setImageViewResource(h.ˊॱ, o.dky.a.ʻ);
            this.ʼ.setImageViewResource(h.ʿॱ, o.dky.a.ॱ);
            this.ʼ.setImageViewResource(h.ˊʼ, o.dky.a.ˋॱ);
            this.ʼ.setImageViewResource(h.ˊʻ, o.dky.a.ˋ);
            this.ʼ.setImageViewResource(h.ˉॱ, o.dky.a.ᐝ);
        }
        if (z) {
            this.ʼ.setImageViewResource(h.ʽˋ, ˊ);
            this.ʼ.setTextViewText(h.ʽᐝ, ˏ(this.ˎ.ॱॱ()));
        }
        CharSequence ॱ = audioBean.ॱ();
        RemoteViews remoteViews = this.ʼ;
        ˊ = h.ˊ;
        if (ॱ == null) {
            ॱ = "";
        }
        remoteViews.setTextViewText(ˊ, ॱ);
        ˋ(this.ॱ);
        ॱᐝ();
        this.ʽ = ˎ.ˊ(this.ʼ).ॱ(this.ʼ).ˊ();
        Glide.ˏ(this.ॱ.getApplicationContext()).ॱ().ˎ(audioBean.ˎ()).ॱ(new a(this)).ˏ(new zy(this.ॱ, h.ˋ, this.ʼ, this.ʽ, 1));
        ˊ(this.ॱ);
        ॱˊ();
        return this.ʽ;
    }

    public void ˊ(AudioBean audioBean) {
        if (audioBean == null) {
            this.ˎ = null;
            ˏ();
            return;
        }
        if (!audioBean.equals(this.ˎ) || this.ʽ == null) {
            ˋ(audioBean);
        }
        ॱ(this.ˎ);
    }

    public void ˏ() {
        if (Logger.ˎ()) {
            Logger.ˏ("AudioNotificationHelper", "cancelNotification");
        }
        this.ʻ.cancel(1);
        ˏॱ();
        ˎ(this.ॱ);
        this.ʽ = null;
    }

    private void ॱ(AudioBean audioBean) {
        if (audioBean != null && this.ʼ != null) {
            CharSequence charSequence;
            String ˏ = epm.ˏ(this.ˏ, this.ˊ, (long) audioBean.ʼ());
            String ˏ2 = epm.ˏ(this.ˏ, this.ˊ, (long) audioBean.ᐝ());
            String str = "";
            if (MinimumFactory.getBoolValue(this.ॱ)) {
                charSequence = "/" + ˏ;
            } else {
                charSequence = "/" + ˏ2;
            }
            this.ʼ.setTextViewText(h.ˏ, charSequence);
        }
    }

    private void ʽ() {
        if (this.ʼ != null && this.ˎ != null) {
            boolean ˋॱ = this.ˎ.ˋॱ();
            if (Logger.ˎ()) {
                Logger.ˏ("AudioNotificationHelper", "isPlaying:" + ˋॱ);
            }
            this.ʼ.setImageViewResource(h.ʼᐝ, ॱ(ˋॱ));
        }
    }

    private void ʻ() {
        int i = 8;
        if (this.ʼ != null) {
            int i2;
            boolean ᐝ = epe.ˏ().ᐝ();
            boolean ʼ = epe.ˏ().ʼ();
            if (Logger.ˎ()) {
                Logger.ˏ("AudioNotificationHelper", "hasNext:" + ᐝ + ",hasPrev:" + ʼ);
            }
            RemoteViews remoteViews = this.ʼ;
            int i3 = h.ˊʻ;
            if (ᐝ) {
                i2 = 0;
            } else {
                i2 = 8;
            }
            remoteViews.setViewVisibility(i3, i2);
            remoteViews = this.ʼ;
            i3 = h.ˉॱ;
            if (ᐝ) {
                i2 = 8;
            } else {
                i2 = 0;
            }
            remoteViews.setViewVisibility(i3, i2);
            RemoteViews remoteViews2 = this.ʼ;
            int i4 = h.ʿॱ;
            if (ʼ) {
                i2 = 0;
            } else {
                i2 = 8;
            }
            remoteViews2.setViewVisibility(i4, i2);
            RemoteViews remoteViews3 = this.ʼ;
            int i5 = h.ˊʼ;
            if (!ʼ) {
                i = 0;
            }
            remoteViews3.setViewVisibility(i5, i);
        }
    }

    public void ˎ(AudioBean audioBean) {
        ˊ(audioBean);
        ʽ();
        ʻ();
        ʼ();
    }

    private void ʼ() {
        if (this.ʽ != null) {
            this.ʻ.notify(1, this.ʽ);
        }
    }

    public void ˊ() {
        this.ˊ = new Formatter(this.ˏ, Locale.getDefault());
        if (this.ʼ != null && this.ˎ != null) {
            this.ʼ.setTextViewText(h.ʽᐝ, ˏ(this.ˎ.ॱॱ()));
            ʼ();
        }
    }

    public void ˋ() {
        ʻ();
        ʼ();
    }

    private PendingIntent ॱॱ() {
        Intent intent = new Intent(this.ॱ, AudioNotificationReceiver.class);
        intent.putExtra(AudioNotificationReceiver.EVENT_KEY, 5);
        return PendingIntent.getBroadcast(this.ॱ, 5, intent, HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR);
    }

    private PendingIntent ˊॱ() {
        if (this.ˎ == null) {
            return null;
        }
        int ॱॱ = this.ˎ.ॱॱ();
        String ˎ = dgm.ˎ(ॱॱ);
        if (cjl.ˋ(ˎ) == null) {
            return null;
        }
        if (ॱॱ == 0 || ॱॱ == 5) {
            Intent intent;
            new cjm(ˎ, null).ॱ(this.ॱ).setFlags(872415232);
            cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
            appDetailActivityProtocol.ˏ(new Request(this.ˎ.ˏ(), this.ˎ.ʻ()));
            Intent ॱ = new cjm("appdetail.activity", appDetailActivityProtocol).ॱ(this.ॱ);
            return PendingIntent.getActivities(this.ॱ, 0, new Intent[]{intent, ॱ}, HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR);
        }
        intent = new Intent(this.ॱ, AudioNotificationJumpActivity.class);
        intent.setFlags(268435456);
        intent.putExtra("service_type", ॱॱ);
        intent.putExtra("detailId", this.ˎ.ˏ());
        intent.putExtra("traceId", this.ˎ.ʻ());
        return PendingIntent.getActivity(this.ॱ, 0, intent, HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR);
    }

    private void ˋ(Context context) {
        ˎ(context, h.ʼᐝ, 1);
        ˎ(context, h.ˊॱ, 4);
        ˎ(context, h.ʿॱ, 2);
        ˎ(context, h.ˊʻ, 3);
    }

    private void ˎ(Context context, @IdRes int i, int i2) {
        Intent intent = new Intent(context, AudioNotificationReceiver.class);
        intent.putExtra(AudioNotificationReceiver.EVENT_KEY, i2);
        PendingIntent broadcast = PendingIntent.getBroadcast(context, i2, intent, HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR);
        if (this.ʼ != null) {
            this.ʼ.setOnClickPendingIntent(i, broadcast);
        }
    }

    public void ˊ(Context context) {
        if (this.ॱॱ == null) {
            this.ॱॱ = new AudioPlayReceiver();
            IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
            intentFilter.addAction("android.intent.action.SCREEN_OFF");
            intentFilter.addAction("android.intent.action.SCREEN_ON");
            intentFilter.addAction("android.intent.action.LOCALE_CHANGED");
            ActivityUtil.registerReceiver(context, intentFilter, this.ॱॱ);
            ll.ˏ(this.ॱ).ˏ(this.ॱॱ, new IntentFilter("com.huawei.systemmanager.action.CHANGE_HOME_COUNTRY"));
        }
    }

    public void ˎ(Context context) {
        if (this.ॱॱ != null) {
            ActivityUtil.unregisterReceiver(context, this.ॱॱ);
            ll.ˏ(this.ॱ).ˋ(this.ॱॱ);
            this.ॱॱ = null;
        }
    }

    private void ॱˊ() {
        epe.ˏ().ˋ(this.ͺ);
    }

    private void ˏॱ() {
        epe.ˏ().ˊ(this.ͺ);
    }

    public void ॱ() {
        if (Logger.ˎ()) {
            Logger.ˏ("AudioNotificationHelper", "changeWhenScreenOn");
        }
        ॱˊ();
        ˎ(epe.ˏ().ॱ());
        ʼ();
    }

    public void ᐝ() {
        if (Logger.ˎ()) {
            Logger.ˏ("AudioNotificationHelper", "changeWhenScreenOff");
        }
        ˏॱ();
    }

    private String ˏ(int i) {
        if (this.ॱ != null) {
            return this.ॱ.getString(dgm.ॱ(i));
        }
        return "";
    }

    private int ˋॱ() {
        if (azc.ˎ().ॱ() > 17) {
            return i.ˊ;
        }
        if (VERSION.SDK_INT < 24) {
            return i.ʼ;
        }
        return i.ˋ;
    }

    private boolean ͺ() {
        boolean ˎ = epv.ˎ();
        if (ˎ && VERSION.SDK_INT >= 24) {
            return false;
        }
        TextView textView = new TextView(this.ॱ);
        if (ˎ) {
            textView.setTextAppearance(this.ॱ, 16973928);
        } else {
            textView.setTextAppearance(this.ॱ, k.ॱ);
        }
        if (erq.ˏ(textView.getCurrentTextColor())) {
            return false;
        }
        return true;
    }

    private int ॱ(boolean z) {
        return z ? this.ᐝ ? o.dky.a.ˏॱ : o.dky.a.ʽ : this.ᐝ ? o.dky.a.ͺ : o.dky.a.ˊॱ;
    }

    private void ॱᐝ() {
        if (this.ʼ != null && this.ॱ != null) {
            Resources resources = this.ॱ.getResources();
            this.ʼ.setContentDescription(h.ʼᐝ, resources.getString(j.ˍ));
            this.ʼ.setContentDescription(h.ˊॱ, resources.getString(j.ᐝॱ));
            this.ʼ.setContentDescription(h.ʿॱ, resources.getString(j.ॱᐝ));
            this.ʼ.setContentDescription(h.ˊʻ, resources.getString(j.ʻॱ));
        }
    }
}
